<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>登录界面</title>
  <link rel="stylesheet" href="./css/style.css">
  <link rel="stylesheet" href="./css/body.css">
  <script src="../lib/axios.js"></script>
  <script src="../layui/layui.all.js"></script>
</head>

<body>
  <div class="container">
    <section id="content">
      <form>
        <h1>账号登录</h1>
        </h1>
        <div>
          <i class="close">X</i>
          <input type="text" placeholder="手机号" id="username" lay-verify="required">
        </div>
        <div>
          <i class="close">X</i>
          <input type="password" placeholder="密码" id="password" lay-verify="required|pwd">
        </div>
        <div>
          <input type="submit" value="登录" class="btn btn-primary" id="js-btn-login">
          <a href="">忘记密码?</a>
          <a href="../02-regbaseCode/reg.html">注册账号</a>
        </div>
      </form>
    </section>
  </div>

  <script src="../lib/jquery.js"></script>
  <script src="./js/login.js"></script>
  <script>
    // const form = document.querySelector('#form1')
    // form.addEventListener('submit', function (e) {
    //   e.preventDefault()



    //   const xhr = new XMLHttpRequest()
    //   xhr.open('POST',
    //     'http://124.223.14.236:3001/api/user/login',
    //   )
    //   xhr.send(fd)

    //   xhr.onreadystatechange = function () {
    //     if (xhr.readyState === 4 && xhr.status === 200) {
    //       console.log(JSON.parse(xhr.responseText))
    //     }
    //   }
    // })

    document.querySelector('form').addEventListener('submit', function (e) {
      e.preventDefault()

      const user = document.querySelector('#username').value.trim()
      const ps = document.querySelector('#password').value.trim()
      if (user.length <= 0 && ps.length <= 0) {
        return alert('请正确输入')
      }
      const url = 'http://124.223.14.236:3001/api/user/login'
      const dataObj = { username: `${username}`, password: `${password}` }

      axios.post(url, dataObj).then(({ data }) => {
        console.log(data);
      })
    })


  </script>
</body>

</html>